package com.hopu.v1.controller.front.attendance;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hopu.v1.pojo.classes.attendance.Attendance;
import com.hopu.v1.pojo.common.R;
import com.hopu.v1.pojo.common.Save;
import com.hopu.v1.pojo.exam.ExamRecords;
import com.hopu.v1.service.front.attendance.FAttendanceService;
import com.hopu.v1.utils.JwtUtils;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: FAttendanceController
 * Description:
 *
 * @Author lh
 * @Create 2024/10/11 14:37
 * @Version 1.0
 */
@RestController
@RequestMapping("/attendance")
public class FAttendanceController {
    @Autowired
    private FAttendanceService fAttendanceService;

    /**
     * 查询学生考勤记录
     * @param request
     * @return
     */
    @GetMapping("/selectStudentAttendance")
    public R select(HttpServletRequest request) {
        String token = request.getHeader("frontToken");
        String studentId = JwtUtils.getUserId(token);
        return R.ok(fAttendanceService.selectStudentAttendance(studentId));
    }

    /**
     * 新增&修改
     * @param attendance
     * @return
     */
    @PostMapping("/add")
    public R add(Attendance attendance) {
        fAttendanceService.add(attendance);

        return R.ok("添加成功");
    }
}
